<%-- 
    Document   : catalogues
    Created on : 05.10.2011, 8:00:02
    Author     : Admin
--%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Collection"%>
<%@page import="javax.rmi.PortableRemoteObject"%>
<%@page import="manufacturerBean.ManufacturerHome"%>
<%@page import="manufacturerBean.Manufacturer"%>
<%@page import="categorybean.Category"%>
<%@page import="categorybean.CategoryHome"%>
<%@page import="GoodsBean.GoodsHome"%>
<%@page import="GoodsBean.Goods"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="DBConnection.ATeamObject"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Каталог товаров</title>
        <%  InitialContext initialContext;
            GoodsHome goodsHome;
            Goods goods;
            Object homeObject;

            CategoryHome categoryHome;
            Category category;
            Object homeObject1;

            Manufacturer manufacturer;
            ManufacturerHome manufacturerHome;
            Object homeObject2;

            ATeamObject ato = new ATeamObject();

            try {
                initialContext = new InitialContext();
                homeObject = initialContext.lookup("GoodsBean");
                goodsHome = (GoodsHome) PortableRemoteObject.narrow(homeObject,
                        GoodsHome.class);

                homeObject1 = initialContext.lookup("CategoryBean");
                categoryHome = (CategoryHome) PortableRemoteObject.narrow(homeObject1,
                        CategoryHome.class);

                homeObject2 = initialContext.lookup("ManufacturerBean");
                manufacturerHome = (ManufacturerHome) PortableRemoteObject.narrow(homeObject2,
                        ManufacturerHome.class);
        %>
    </head>
    <body background="1.jpg" bgproperties="fixed">
        <h4><a href="index.jsp">Главная</a>> <a href="catalogues.jsp">Каталог товаров</a></h4>
        <table>
            <tr>
                <td>
                    <form name="MainPageForm" method="post" action="findResults.jsp">
                        <center>
                            <h2>Поиск товаров</h2>
                            <table>
                                <tr>
                                    <td>
                                        <b>Наименование товара</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="text" name="GoodsName" size="50">
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="radio" name="SearchingCriteria" value="0" checked="true"> Совпадает
                                    </td>
                                </tr>
                                <tr>
                                    <td> 
                                        <input type="radio" name="SearchingCriteria" value="1"> Содержит
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <b>Цена товара</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="text" name="GoodsPriceFrom" size="10">
                                        <input type="text" name="GoodsPriceTo" size="10" id="txt">
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="radio" name="GoodsPriceOptions" value=">" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Больше чем<br>
                                        <input type="radio" name="GoodsPriceOptions" value="<" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Меньше чем<br>
                                        <input type="radio" name="GoodsPriceOptions" value="=" checked="true" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Равно значению<br>
                                        <input type="radio" name="GoodsPriceOptions" value="BETWEEN" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Лежит в диапазоне<br>
                                    </td>
                                </tr>
                                <tr>
                                    <td><b>Производитель</b><td>
                                </tr>
                                <%  Collection allManufacturer = manufacturerHome.findAll();
                                    Iterator iter = allManufacturer.iterator();
                                %>
                                <tr>
                                    <td>
                                        <select name="ManufacturerSelect">
                                            <option></option>
                                            <% while (iter.hasNext()) {
                                                   manufacturer = (Manufacturer) iter.next();
                                            %>
                                                   <option value="<%= manufacturer.getObjectId()%>"><%= manufacturer.getName()%></option>
                                            <% }%>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td><b>Категория товара</b></td>
                                </tr>
                                <% Collection allCategory = categoryHome.findAll();
                                   iter = allCategory.iterator();
                                %>
                                <tr>
                                    <td>
                                        <select name="GoodsCategorySelect">
                                            <option></option>
                                            <% while (iter.hasNext()) {
                                                   category = (Category) iter.next();

                                            %>
                                                   <option value="<%= category.getObjectId()%>"><%= category.getName()%></option>
                                            <% }%>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="submit" value="Поиск">
                                        <input type="reset" value="Очистить">
                                    </td>
                                </tr> 
                            </table>
                        </center>
                    </form>
                </td>
                <td valign="top">
                    <h1>Категории товаров</h1>
                    <form action="catalogues.jsp" method="POST">
                        <%  if (!request.getParameterMap().isEmpty()) {
                                for (String catID : request.getParameterValues("delCategories")) {
                                    category = categoryHome.findByPrimaryKey(Integer.parseInt(catID));
                                    category.remove();
                                }
                            }
                            allCategory = categoryHome.findAll();
                            iter = allCategory.iterator();
                            while (iter.hasNext()) {
                                category = (Category) iter.next();
                        %>
                        <p>
                            <a href="goodsList.jsp?catID=<%= category.getObjectId()%>&catName=<%= category.getName()%>">
                                <input type="checkbox" name="delCategories" value="<%= category.getObjectId()%>" />        
                            <%= category.getName() %>
                            </a>
                        </p>
                        <% } %>
                        <p><input type="submit" value="Удалить отмеченные" name="delCategoies" /></p>     
                    </form>
                    <form action="addCategory.jsp" method="POST">
                        <input type="submit" value="Добавить новую категорию" name="add" />
                    </form>
                </td>
            </tr>


        </table>  

        <% } catch (Exception e) {
                e.printStackTrace(System.err);
            }
        %>                            
    </body>
</html>
